/**
 * @author 黄波
 * 创建日期：2011Sep 28, 2011
 * TODO// N/A
 */
package com.platform.course.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.constant.ResponseCode;
import com.platform.course.bo.CourseBo;

/**
 * 批量删除课程信息
 */
public class BatchDelCourseAction extends CourseSupport {

	private String[] ids;
	private String msg;
	private boolean success;
	public String[] getIds() {
		return ids;
	}
	public void setIds(String[] ids) {
		this.ids = ids;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public String execute() throws Exception {
		if(ids == null || ids.length == 0) {
			msg = ResponseCode.FAILURE_BATCH_ID_NULL;
		} else {
			CourseBo bo = CourseBo.getInstance();
			for(String id : ids) {
				bo.deleteCourse(id);
			}
			msg = ResponseCode.SUCCESS_BATCH_DELETE;
		}

		success = true;
		HashMap map = new HashMap();
		map.put("msg", msg);
		map.put("success", success);
		JSONObject json = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		out.println(json);
		out.flush();
		out.close();
		return null;
	}
}
